#pragma once
#include"usart.h"
#include"usart_stub.h"
#include"serial/serial.h"
#include <optional>
#include <memory>

namespace OHOS{
namespace Usart_Standard{

class UsartAbility:public SystemAbility,public UsartAbilityStub{
	DECLARE_SYSTEM_ABILITY(UsartAbility);
public:
	UsartAbility(int32_t saId, bool runOnCreate);
	~UsartAbility();

	virtual int open(const std::string& name) override;
	virtual int close(const std::string& name) override;
	virtual bool is_open(const std::string& name) override;

    virtual int write(const std::string& name,const std::string& data) override;
	
	virtual std::string read(const std::string& name,size_t bytes) override;
	virtual std::string readline(const std::string& name) override;

	virtual void begin_read_loop(const std::string& name)override;
	virtual void end_read_loop(const std::string& name)override;
	virtual std::string read_from_looper(const std::string& name)override;
	
	void OnDump() override;
    void OnStart() override;
    void OnStop() override;
	//void OnDebug()override;
	//void OnTest()override;
	virtual void OnAddSystemAbility(int32_t systemAbilityId, const std::string& deviceId)override;
	// void OnAddSystemAbility(int32_t systemAbilityId, const std::string& deviceId,
    //     const sptr<IRemoteObject>& ability)override;
	//using port_handle = std::shared_ptr<serial::Serial>;
	using port_handle = serial::Serial *;
private:
	//static std::map<std::string,port_handle> ports;
	std::optional<port_handle> get_handle_and_assert_open(const std::string& name);
};//class UsartAbility

}//namespace Usart_Standard
}//namespace OHOS